<template>
  <div class="member-order-page">
    <XtxTabs v-model="activeName" @tab-click="tabClick">
      <XtxTabsPanel
        v-for="item in orderStatus"
        :key="item.name"
        :label="item.label"
        :name="item.name"
      />
    </XtxTabs>
    <div class="order-list">
      <OrderItem v-for="item in orderList" :key="item.id" :order="item" />
    </div>
  </div>
</template>
<script>
import { reactive, ref } from 'vue'
import { reqFindOrderList } from '@/api/order'
import { orderStatus } from '@/constants'
import OrderItem from './components/order-item'
export default {
  name: 'MemberOrderPage',
  components: {
    OrderItem
  },
  setup() {
    const activeName = ref('all')
    // #1 订单列表
    const orderList = ref([])
    // #2 查询订单参数
    const requestParams = reactive({
      orderState: 0,
      page: 1,
      pageSize: 5
    })
    // #3 查询订单
    async function getOrderList() {
      const res = await reqFindOrderList(requestParams)
      orderList.value = res.result.items
    }
    getOrderList()

    const tabClick = ({ index }) => {
      requestParams.orderState = index
      getOrderList()
    }
    return { activeName, orderStatus, orderList, tabClick }
  }
}
</script>

<style scoped lang="less">
.order-list {
  background: #fff;
  padding: 20px;
}
</style>
